package com.senjoeson.wanandroid.utils;

/**
 * @author senjoeson
 * @date 2018/4/4
 */

public class TimeUtils {


    public static String parseTime(long publishTime) {
        long time = System.currentTimeMillis() - publishTime;
        long minute = 1000 * 60;
        long hour = 60 * minute;
        long day = 24 * hour;
        long month=30*day;
        long year=12*month;
        if(getWholeNumber(time,year)>=1){
                return getWholeNumber(time,year)+"年前";
        }else if(getWholeNumber(time,month)>=1){

            return getWholeNumber(time,month)+"月前";

        }else if(getWholeNumber(time,day)>=1){

            return getWholeNumber(time,day)+"天前";

        }else if(getWholeNumber(time,hour)>=1){

            return getWholeNumber(time,hour)+"小时前";

        }else if(getWholeNumber(time,minute)>=1){

            return getWholeNumber(time,minute)+"分钟前";

        }else {

            return getWholeNumber(time,1000)+"秒前";
        }
    }



    private static int getWholeNumber(long time,long target){
        return (int)(time/target);
    }
}
